from functools import wraps
from .serializers import Serializer
from .utils import pack_all
from typing import Callable


def mashal_with(serializer: Serializer, pack_all: Callable = pack_all):
    def pack(func):
        @wraps(func)
        def handle(*args, **kwargs):
            res = func(*args, **kwargs)
            return pack_all(serializer.pack(res))

        return handle

    return pack
